package com.ruoyi.zhjd.collect.modules.piece.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.zhjd.collect.modules.dosage.entity.CollectDosageEntity;
import com.ruoyi.zhjd.collect.modules.dosage.service.LCollectDosageService;
import com.ruoyi.zhjd.collect.modules.piece.dto.CollectPieceDto;
import com.ruoyi.zhjd.collect.modules.piece.dto.PieceAndDosageDto;
import com.ruoyi.zhjd.collect.modules.piece.dto.StatisticsPieceDto;
import com.ruoyi.zhjd.collect.modules.piece.entity.CollectPieceEntity;
import com.ruoyi.zhjd.collect.modules.piece.mapper.LCollectPieceMapper;
import com.ruoyi.zhjd.collect.modules.piece.service.LCollectPieceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * 盘信息
 */
@Service
public class LCollectPieceServiceImpl extends ServiceImpl<LCollectPieceMapper, CollectPieceEntity>
        implements LCollectPieceService {

//    @Autowired
//    private BaseServiceComponent baseServiceComponent;
    @Autowired
    private LCollectDosageService LCollectDosageService;

    @Override
    public IPage<CollectPieceDto> page(Map<String, Object> params) {
        IPage<CollectPieceDto> page = null;
        return baseMapper.query(page, params);
    }

    @Override
    public List<CollectPieceDto> list(Map<String, Object> params) {
        return baseMapper.query(params);
    }

    /**
     * 盘数据统计
     *
     * @param params 查询条件
     */
    @Override
    public IPage<StatisticsPieceDto> statisticsPiece(Map<String, Object> params) {
        IPage<StatisticsPieceDto> page = null;
        return baseMapper.statisticsPiece(page, params);
    }

    /**
     * 盘数据统计
     *
     * @param params 查询条件
     */
    @Override
    public IPage<PieceAndDosageDto> pagePieceAndDosage(Map<String, Object> params) {
        IPage<PieceAndDosageDto> page = null;
        IPage<PieceAndDosageDto> pageData = baseMapper.queryPage(page, params);
        //遍历每一个盘次，获取用料情况
        for (PieceAndDosageDto dto : pageData.getRecords()) {
            List<CollectDosageEntity> dosageList = LCollectDosageService.queryByPieceId(dto.getPkId());
            for (int i = 1; i <= dosageList.size(); i++) {
                CollectDosageEntity d = dosageList.get(i - 1);
                switch (i) {
                    case 1:
                        dto.setMaterial1(d.getMaterial());
                        dto.setSpec1(d.getSpec());
                        dto.setFactAmnt1(d.getFactAmnt());
                        dto.setWatFull1(d.getWatFull());
                        dto.setRecAmnt1(d.getRecAmnt());
                        dto.setPlanAmnt1(d.getPlanAmnt());
                        break;
                    case 2:
                        dto.setMaterial2(d.getMaterial());
                        dto.setSpec2(d.getSpec());
                        dto.setFactAmnt2(d.getFactAmnt());
                        dto.setWatFull2(d.getWatFull());
                        dto.setRecAmnt2(d.getRecAmnt());
                        dto.setPlanAmnt2(d.getPlanAmnt());
                        break;
                    case 3:
                        dto.setMaterial3(d.getMaterial());
                        dto.setSpec3(d.getSpec());
                        dto.setFactAmnt3(d.getFactAmnt());
                        dto.setWatFull3(d.getWatFull());
                        dto.setRecAmnt3(d.getRecAmnt());
                        dto.setPlanAmnt3(d.getPlanAmnt());
                        break;
                    case 4:
                        dto.setMaterial4(d.getMaterial());
                        dto.setSpec4(d.getSpec());
                        dto.setFactAmnt4(d.getFactAmnt());
                        dto.setWatFull4(d.getWatFull());
                        dto.setRecAmnt4(d.getRecAmnt());
                        dto.setPlanAmnt4(d.getPlanAmnt());
                        break;
                    case 5:
                        dto.setMaterial5(d.getMaterial());
                        dto.setSpec5(d.getSpec());
                        dto.setFactAmnt5(d.getFactAmnt());
                        dto.setWatFull5(d.getWatFull());
                        dto.setRecAmnt5(d.getRecAmnt());
                        dto.setPlanAmnt5(d.getPlanAmnt());
                        break;
                    case 6:
                        dto.setMaterial6(d.getMaterial());
                        dto.setSpec6(d.getSpec());
                        dto.setFactAmnt6(d.getFactAmnt());
                        dto.setWatFull6(d.getWatFull());
                        dto.setRecAmnt6(d.getRecAmnt());
                        dto.setPlanAmnt6(d.getPlanAmnt());
                        break;
                    case 7:
                        dto.setMaterial7(d.getMaterial());
                        dto.setSpec7(d.getSpec());
                        dto.setFactAmnt7(d.getFactAmnt());
                        dto.setWatFull7(d.getWatFull());
                        dto.setRecAmnt7(d.getRecAmnt());
                        dto.setPlanAmnt7(d.getPlanAmnt());
                        break;
                    case 8:
                        dto.setMaterial8(d.getMaterial());
                        dto.setSpec8(d.getSpec());
                        dto.setFactAmnt8(d.getFactAmnt());
                        dto.setWatFull8(d.getWatFull());
                        dto.setRecAmnt8(d.getRecAmnt());
                        dto.setPlanAmnt8(d.getPlanAmnt());
                        break;
                    case 9:
                        dto.setMaterial9(d.getMaterial());
                        dto.setSpec9(d.getSpec());
                        dto.setFactAmnt9(d.getFactAmnt());
                        dto.setWatFull9(d.getWatFull());
                        dto.setRecAmnt9(d.getRecAmnt());
                        dto.setPlanAmnt9(d.getPlanAmnt());
                        break;
                    case 10:
                        dto.setMaterial10(d.getMaterial());
                        dto.setSpec10(d.getSpec());
                        dto.setFactAmnt10(d.getFactAmnt());
                        dto.setWatFull10(d.getWatFull());
                        dto.setRecAmnt10(d.getRecAmnt());
                        dto.setPlanAmnt10(d.getPlanAmnt());
                        break;
                    case 11:
                        dto.setMaterial11(d.getMaterial());
                        dto.setSpec11(d.getSpec());
                        dto.setFactAmnt11(d.getFactAmnt());
                        dto.setWatFull11(d.getWatFull());
                        dto.setRecAmnt11(d.getRecAmnt());
                        dto.setPlanAmnt11(d.getPlanAmnt());
                        break;
                    case 12:
                        dto.setMaterial12(d.getMaterial());
                        dto.setSpec12(d.getSpec());
                        dto.setFactAmnt12(d.getFactAmnt());
                        dto.setWatFull12(d.getWatFull());
                        dto.setRecAmnt12(d.getRecAmnt());
                        dto.setPlanAmnt12(d.getPlanAmnt());
                        break;
                    case 13:
                        dto.setMaterial13(d.getMaterial());
                        dto.setSpec13(d.getSpec());
                        dto.setFactAmnt13(d.getFactAmnt());
                        dto.setWatFull13(d.getWatFull());
                        dto.setRecAmnt13(d.getRecAmnt());
                        dto.setPlanAmnt13(d.getPlanAmnt());
                        break;
                    case 14:
                        dto.setMaterial14(d.getMaterial());
                        dto.setSpec14(d.getSpec());
                        dto.setFactAmnt14(d.getFactAmnt());
                        dto.setWatFull14(d.getWatFull());
                        dto.setRecAmnt14(d.getRecAmnt());
                        dto.setPlanAmnt14(d.getPlanAmnt());
                        break;
                    case 15:
                        dto.setMaterial15(d.getMaterial());
                        dto.setSpec15(d.getSpec());
                        dto.setFactAmnt15(d.getFactAmnt());
                        dto.setWatFull15(d.getWatFull());
                        dto.setRecAmnt15(d.getRecAmnt());
                        dto.setPlanAmnt15(d.getPlanAmnt());
                        break;
                }
            }
        }

        return pageData;
    }

}
